import 'package:flutter/material.dart';

/// 创建Item Widget
class BusinessTaskItem extends StatelessWidget {
  final String title;
  final Widget state;
  final List<Widget> subRowList;

  const BusinessTaskItem({Key key, @required this.title, @required this.state, this.subRowList = const []}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    List<Widget> _list = [];
    List<Widget> _subRowList = this.subRowList.where((element) => element != null).toList();
    for (int i = 0; i < _subRowList.length; i++) {
      _list.add(_subRowList[i]);
      if (i != _subRowList.length - 1) _list.add(SizedBox(height: 4));
    }
    return DefaultTextStyle(
      style: Theme.of(context).textTheme.subtitle2,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildTitle(context),
          SizedBox(height: 4),
          ..._list,
        ],
      ),
    );
  }

  /// 获取标题
  Widget _buildTitle(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(this.title, softWrap: false, overflow: TextOverflow.ellipsis, style: Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 14)),
        this.state,
      ],
    );
  }
}
